//
//  WJWMainTabBarController.swift
//  SwiftWeibo
//
//  Created by 万嘉伟 on 16/7/18.
//  Copyright © 2016年 万嘉伟. All rights reserved.
//

import UIKit

class WJWMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

           //定义tabbar
        let mainTabBar=WJWMainTabBar()
        //定义闭包
        mainTabBar.composeCallback={() ->Void in
            
        }
        //简介赋值KVC
        self.setValue(mainTabBar, forKey: "tabBar")
        addChildViewControllers()
    }
    /**
    *  子控制器
    */
    func addChildViewControllers() {
        //添加子控制器
        //首页
        let homeVC=WJWHomeTableViewController()
        addChildViewController(homeVC,title:"首页",imageName:"tabbar_home")
        //消息
        let messageVC=WJWMessageTableViewController()
        addChildViewController(messageVC,title: "消息",imageName: "tabbar_message_center")
        //发现
        let discoveryVC=WJWTDiscoveryViewController()
        addChildViewController(discoveryVC, title: "发现", imageName:"tabbar_discover")
        //我
        let profileVC=WJWProfileTableViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
    }
    /**
     自己写的一个方法
     控制器
     title
     图片名称
     */
    func addChildViewController(controller: UIViewController,title:String,imageName:String) {
        //设置标题
        controller.title=title
        //点击以后字体变成了橘黄色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor .orangeColor()], forState: UIControlState.Normal)
        controller.tabBarItem.image=UIImage(named: imageName)
        //拼接选中图片的名称
        let selectedImageName = imageName + "_selected"
        //设置选中的图片
        controller.tabBarItem.selectedImage=UIImage(named: selectedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
    }
}
